{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 多态： 不同的 子类对象 调用相同的 父类方法，产生不同的执行结果\n",
    "#      – 多态 可以 增加代码的灵活度\n",
    "#      – 以 继承 和 重写父类方法 为前提\n",
    "#      – 是调用方法的技巧，不会影响到类的内部设计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# 需求\n",
    "# 1 在 Dog 类中封装方法 game\n",
    "# – 普通狗只是简单的玩耍\n",
    "# 2 定义 XiaoTianDog 继承自 Dog，并且重写 game 方法\n",
    "# – 哮天犬需要在天上玩耍\n",
    "# 3 定义 Person 类，并且封装一个 和狗玩 的方法\n",
    "# – 在方法内部，直接让 狗对象 调用 game 方法"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "哮天犬需要在天上耍\n",
      "普通狗只是简单地玩耍\n"
     ]
    }
   ],
   "source": [
    "class Dog:\n",
    "    def game(self):\n",
    "        print(\"普通狗只是简单地玩耍\")\n",
    "\n",
    "class XiaoTianDog(Dog):\n",
    "    def game(self):\n",
    "        print(\"哮天犬需要在天上耍\")\n",
    "\n",
    "class Person:\n",
    "    def play(self,dog:Dog):\n",
    "        dog.game()\n",
    "\n",
    "wangcai = XiaoTianDog()\n",
    "ru = Dog()\n",
    "xiaoming = Person()\n",
    "xiaoming.play(wangcai)\n",
    "xiaoming.play(ru)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}